from application.enumeration.ContentTypeEnum import ContentTypeEnum
from application.dependency.TokenDependency import verify_token
from application.entity.CommentEntity import CommentAdd
from application.util.ResponseUtil import ResponseUtil
from application.logic import CommentLogic
from fastapi import APIRouter, Depends, Query
from fastapi.responses import JSONResponse

router: APIRouter = APIRouter(prefix="/comment", tags=["评论"])


@router.post("/add", summary="添加评论")
async def add_comment(comment_add: CommentAdd, user_id: int = Depends(verify_token)) -> JSONResponse:
    await CommentLogic.add_comment(user_id=user_id, comment_add=comment_add)
    return ResponseUtil().success()


@router.post("/delete/{comment_id:int}", summary="根据评论ID删除评论")
async def delete_comment(comment_id: int, content_type: ContentTypeEnum = Query(default=ContentTypeEnum.NOTE),
                         user_id: int = Depends(verify_token)) -> JSONResponse:
    await CommentLogic.delete_comment_by_id(comment_id=comment_id, user_id=user_id, content_type=content_type)
    return ResponseUtil().success()


@router.get("/list", summary="根据文章ID获取评论列表")
async def get_list(target_id: int, page: int = Query(default=1, ge=1), page_size: int = Query(default=10, ge=1),
                   content_type: ContentTypeEnum = Query(default=ContentTypeEnum.NOTE)) -> JSONResponse:
    return ResponseUtil(data=await CommentLogic.get_list(target_id=target_id, content_type=content_type,
                                                         page_size=page_size, page=page)).success()
